/**********************************************************
 * RegistrationPageOptionsAction.java.java
 * Created by Ashutosh
 * Last modified Date: Sep 18, 2008 10:49:22 AM by Ashutosh
 * Revision: <svn revision #>
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/

package com.printeverywhere.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.printeverywhere.delegator.UserRegistrationOptionsDelegator;
import com.printeverywhere.dto.UserRegistrationOptions;

/**
 * The Class RegistrationPageOptionsAction.
 */
public class RegistrationPageOptionsAction extends AdminSystemSetup {

	/** Logger for this class. */
	private static final Logger logger = Logger
			.getLogger(RegistrationPageOptionsAction.class);

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/** The option. */
	private List<String> option = new ArrayList<String>();

	/** The optionslist. */
	List<UserRegistrationOptions> optionslist = null;

	/** The my entities map. */
	private Map<String, UserRegistrationOptions> myEntitiesMap;

	/** The user registration. */
	private UserRegistrationOptions userRegistration;

	/**
	 * Show.
	 *
	 * @return the string
	 *
	 * @throws Exception
	 *             the exception
	 */
	public String show() throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("show() - start"); //$NON-NLS-1$
		}
			this.optionslist = UserRegistrationOptionsDelegator.getList();
			this.myEntitiesMap = new HashMap<String, UserRegistrationOptions>();
			for (UserRegistrationOptions userRegistration : this
					.getOptionslist()) {
				this.myEntitiesMap.put(String.valueOf(userRegistration.getId()),userRegistration);
			}
		
		if (logger.isDebugEnabled()) {
			logger.debug("show() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	/**
	 * Save option.
	 *
	 * @return the string
	 */
	public String saveOption() {
		if (logger.isDebugEnabled()) {
			logger.debug("saveOption() - start"); //$NON-NLS-1$
		}

		for (UserRegistrationOptions myEntity : this.getMyEntitiesMap().values()) {
			UserRegistrationOptionsDelegator.update(myEntity);
		}
			optionslist = UserRegistrationOptionsDelegator.getList();
		if (logger.isDebugEnabled()) {
			logger.debug("saveOption() - end"); //$NON-NLS-1$
		}
		return SUCCESS;
	}

	/**
	 * Gets the my entities map.
	 *
	 * @return the my entities map
	 */
	public Map<String, UserRegistrationOptions> getMyEntitiesMap() {
		return myEntitiesMap;
	}

	/**
	 * Sets the my entities map.
	 *
	 * @param myEntitiesMap
	 *            the my entities map
	 */
	public void setMyEntitiesMap(
			Map<String, UserRegistrationOptions> myEntitiesMap) {
		this.myEntitiesMap = myEntitiesMap;
	}

	/**
	 * Gets the optionslist.
	 *
	 * @return the optionslist
	 */
	public List<UserRegistrationOptions> getOptionslist() {
		return optionslist;
	}

	/**
	 * Sets the optionslist.
	 *
	 * @param optionslist
	 *            the new optionslist
	 */
	public void setOptionslist(List<UserRegistrationOptions> optionslist) {
		this.optionslist = optionslist;
	}

	/**
	 * Gets the option.
	 *
	 * @return the option
	 */
	public List<String> getOption() {
		return option;
	}

	/**
	 * Sets the option.
	 *
	 * @param option
	 *            the new option
	 */
	public void setOption(List<String> option) {
		this.option = option;
	}

	/**
	 * Gets the user registration.
	 *
	 * @return the user registration
	 */
	public UserRegistrationOptions getUserRegistration() {
		return userRegistration;
	}

	/**
	 * Sets the user registration.
	 *
	 * @param userRegistration
	 *            the new user registration
	 */
	public void setUserRegistration(UserRegistrationOptions userRegistration) {
		this.userRegistration = userRegistration;
	}

	/**
	 * Gets the options list.
	 *
	 * @return the options list
	 */
	public List<UserRegistrationOptions> getOptionsList() {
		return optionslist;
	}

	/**
	 * Sets the options list.
	 *
	 * @param optionslist
	 *            the new options list
	 */
	public void setOptionsList(List<UserRegistrationOptions> optionslist) {
		this.optionslist = optionslist;
	}

	/**
	 * Gets the user registration.
	 *
	 * @return the user registration
	 */
	public UserRegistrationOptions getuserRegistration() {
		return userRegistration;
	}

	/**
	 * Sets the languages.
	 *
	 * @param userRegistration
	 *            the new languages
	 */
	public void setLanguages(UserRegistrationOptions userRegistration) {
		this.userRegistration = userRegistration;
	}
}